//
// Ephi - simulation of magnetic fields and particles
// Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
// For more information please see http://www.mare.ee/indrek/ephi/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "ephi.hpp"

// make pretty pictures

#define RADIUS 0.1
#define DIST 0.05
#define ELEMENTS 5
#define CURRENT 5000
#define WIRE_RADIUS 0.008

int main (int argc, char *argv[])
{
  struct a { int w; int h;};
  a wh[] = {{160, 120}, {800, 600}, {1024, 768}, {1280, 1024}, {0, 0}};

  {
    Statics statics;
    ElectroDynamics dyn(statics);
    make_solenoid (statics, 5, 0.1, 0.008, 0.05, 5000);
    char path[128];
    for ( a *it = wh; it->w != 0; it++ )
      {
        Screen screen(it->w, it->h, 0.9, 0.9 * it->h / it->w);
        Scene scene(dyn);
        printf ("Calculating solenoid..\n");
        scene.calc (screen);
        printf ("Calc done!\n");
        // LIC, logcolored full range
        scene.set_coloring (0, true);
        scene.render_lic (screen);
        sprintf (path, "solenoid_wallpaper_%ux%u_blic_logcolor_full.bmp", it->w, it->h);
        screen.write (path);
        // LIC, colored full range
        scene.set_coloring (0);
        scene.render_lic (screen);
        sprintf (path, "solenoid_wallpaper_%ux%u_blic_color_full.bmp", it->w, it->h);
        screen.write (path);
        // BMAP, colored
        scene.set_coloring (0);
        scene.render_map (screen);
        sprintf (path, "solenoid_wallpaper_%ux%u_bmap_color_full.bmp", it->w, it->h);
        screen.write (path);
        // BMAP, logcolored
        scene.set_coloring (0, true);
        scene.render_map (screen);
        sprintf (path, "solenoid_wallpaper_%ux%u_bmap_logcolor_full.bmp", it->w, it->h);
        screen.write (path);
      }
  }

  {
    Statics statics;
    ElectroDynamics dyn(statics);
    make_polywell_cube (statics, 0.3, 0.02, 0.005, 100000);
    char path[128];
    for ( a *it = wh; it->w != 0; it++ )
      {
        Screen screen(it->w, it->h, 1.5, 1.5 * it->h / it->w);
        Scene scene(dyn);
        printf ("Calculating cube polywell..\n");
        scene.calc (screen);
        printf ("Calc done!\n");
        // LIC, logcolored full range
        scene.set_coloring (0, true);
        scene.render_lic (screen);
        sprintf (path, "polywell_cube_wallpaper_%ux%u_blic_logcolor_full.bmp", it->w, it->h);
        screen.write (path);
        // LIC, colored full range
        scene.set_coloring (0);
        scene.render_lic (screen);
        sprintf (path, "polywell_cube_wallpaper_%ux%u_blic_color_full.bmp", it->w, it->h);
        screen.write (path);
        // BMAP, colored
        scene.set_coloring (0);
        scene.render_map (screen);
        sprintf (path, "polywell_cube_wallpaper_%ux%u_bmap_color_full.bmp", it->w, it->h);
        screen.write (path);
        // BMAP, logcolored
        scene.set_coloring (0, true);
        scene.render_map (screen);
        sprintf (path, "polywell_cube_wallpaper_%ux%u_bmap_logcolor_full.bmp", it->w, it->h);
        screen.write (path);
        // BMAP, logcolored, stepped
        scene.set_coloring (32, true);
        scene.render_map (screen);
        sprintf (path, "polywell_cube_wallpaper_%ux%u_bmap_logcolor_step.bmp", it->w, it->h);
        screen.write (path);
      }
  }

  return 0;
}

